package servlet;

import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.db.conn;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class orders_Edit extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public orders_Edit() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	//编辑订单信息
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		PrintWriter out = response.getWriter();

		conn cn = new conn();

		String f=request.getParameter("f");

        String id=request.getParameter("id");
	

		if(f==null)
		{
			String ono=request.getParameter("txt_ono");
			String rid=request.getParameter("se_rid");
			String sdate=request.getParameter("txt_sdate");
			String edate=request.getParameter("txt_edate");
			String omoney=request.getParameter("txt_omoney");
			String smoney=request.getParameter("txt_smoney");
			String ymoney=request.getParameter("txt_ymoney");
			String mid=request.getParameter("txt_mid");
			String mname=request.getParameter("txt_mname");
			String tel=request.getParameter("txt_tel");
			String cardno=request.getParameter("txt_cardno");
			String oflag=request.getParameter("txt_oflag");


			String sql="update orders set ono = '"+ono+"',rid = "+rid+",sdate = '"+sdate+"',edate = '"+edate+"',omoney = '"+omoney+"',smoney = "+smoney+",ymoney = "+ymoney+",mid = "+mid+",mname = '"+mname+"',tel = '"+tel+"',cardno = '"+cardno+"',oflag = '"+oflag+"' where ono='"+id+"'";

		




			int i=cn.update(sql);
			
			out.println("<script>");
			out.println("alert('操作成功');");
			out.println("window.location='admin/orders/orders_Manage.jsp'");
			out.println("</script>");
		}
		else if(f.equals("2"))
		{



			String sql="update orders set oflag = '已支付' where ono='"+id+"'";

		




			int i=cn.update(sql);
			
			JSONArray jsonarray = new JSONArray();
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("jieguo", 1);
			jsonarray.add(jsonobj);
			out = response.getWriter();
			out.println(jsonarray);
		}

	
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

